﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nacos.AspNetCore;
using ProjectManApi.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectManApi.Controllers.Xccz
{
    public class Xccz : MvcControllerBase
    {
        private readonly INacosServerManager _serverManager;
        public Xccz(INacosServerManager serverManager) : base(serverManager)
        {
            _serverManager = serverManager;

        }
        /// <summary>
        /// 资产报废
        /// </summary>
        /// <param name="gsdm"></param>
        /// <param name="time1"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> SelectZCBF(string gsdm, DateTime time1)
        {
            DataTable info = null;
            try
            {
                int count = await BusinessRule.XCCZ.xccz.InsertZCBF(gsdm, time1);
                if (count >=-1)
                {
                     info = await BusinessRule.XCCZ.xccz.selectZCBF(gsdm,time1);
                    return Success(info);
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
            return Success(info);
        }
        /// <summary>
        /// 资产购置
        /// </summary>
        /// <param name="gsdm"></param>
        /// <param name="time1"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> SelectZCGZ(string gsdm, DateTime time1)
        {
            DataTable info = null;
            try
            {
                int count = await BusinessRule.XCCZ.xccz.InsertZCGM(gsdm, time1);
                if (count >= -1)
                {
                    info = await BusinessRule.XCCZ.xccz.selectZCGM(gsdm, time1);
                    return Success(info);
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
            return Success(info);
        }
        /// <summary>
        /// 资产折旧汇总表
        /// </summary>
        /// <param name="gsdm"></param>
        /// <param name="time1"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> SelectZCPZ(string gsdm, DateTime time1)
        {
            DataTable info = null;
            try
            {
                int count = await BusinessRule.XCCZ.xccz.InsertZJPZ(gsdm, time1);
                if (count >= -1)
                {
                    info = await BusinessRule.XCCZ.xccz.selectZJPZ(gsdm, time1);
                    return Success(info);
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
            return Success(info);
        }
        /// <summary>
        /// 资产折旧明细类别
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetZJNX()
        {
            DataTable info = null;
            try
            {
               
                    info = await BusinessRule.XCCZ.xccz.GetZJNX();
                    return Success(info);
                
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
            return Success(info);
        }
        /// <summary>
        /// 查看资产折旧明细表
        /// </summary>
        /// <param name="gsdm"></param>
        /// <param name="time1"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> SelectZCZJMX(string gsdm, DateTime time1,string lbdm)
        {
            DataTable info = null;
            try
            {
                int count = await BusinessRule.XCCZ.xccz.InsertZCZJMX(gsdm, time1);
                if (count >= -1)
                {
                    info = await BusinessRule.XCCZ.xccz.selectZCZJMX(gsdm, time1,lbdm);
                    return Success(info);
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
            return Success(info);
        }

    }
}
